import { Component, OnInit } from '@angular/core';
import { FileHistoryService } from "./file-history.service";
import { Util } from '../../../../common/util';
import * as _ from 'lodash'
@Component({
  selector: 'app-file-history',
  templateUrl: './file-history.component.html',
  styleUrls: ['./file-history.component.scss'],
  providers: [FileHistoryService]
})
export class FileHistoryComponent implements OnInit {
  // 基金信息
  public fileHistoryVersions: any;
  // 附件历史数据
  public fileHistoryData: any;
  constructor(
    public fileHistoryService: FileHistoryService
  ) {
  }

  ngOnInit() {
    this.showHistoryVersion();
  }
  // 下载附件
  downLoadFile(item) {
    if (item.nAttachNo) {
      Util.attachDownload([item.nAttachNo]);
    } else {
      window['swal']("提示", "暂无文件下载", "warning");
    }
  }
  //  截取文件名称类型
  Intercept(item) {
    let str = item;
    if (str) {
      let arr = str.split('.');
      let newarr = arr[arr.length - 1];
      return newarr;
    }
  }
  // 查看历史文件
  showHistoryVersion() {
    let that = this;
    // this.activeFileType = item.sParentCode;
    this.fileHistoryService.getFileHistory(this.fileHistoryVersions.nAttachNo).subscribe(data => {
      if (data) {
        that.fileHistoryData = data;
        // 附件后缀
        _.forEach(that.fileHistoryData, function (item) {
          item["fileType"] = that.Intercept(item.sAttachName);
        })
        window['$']("#detail-his-list").modal('show');
      } else {
        window['swal']("提示", "暂无文件", "warning");
      }
    })
  }
}
